import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';

const isProduction = process.env.NODE_ENV === 'production';

export default {
  input: 'src/index.ts',
  output: [
    // ES模块格式（支持按需引入）
    {
      file: 'dist/index.esm.js',
      format: 'es',
      sourcemap: !isProduction,
      exports: 'named'
    },
    // CommonJS格式（Node.js环境）
    {
      file: 'dist/index.cjs.js',
      format: 'cjs',
      sourcemap: !isProduction,
      exports: 'named'
    },
    // UMD格式（浏览器全局变量）
    {
      file: 'dist/index.umd.js',
      format: 'umd',
      name: 'ZssOlMap',
      sourcemap: !isProduction,
      exports: 'named',
      globals: {
        'ol': 'ol'
      }
    },
    // 压缩版UMD（用于HTML直接引入）
    {
      file: 'dist/index.umd.min.js',
      format: 'umd',
      name: 'ZssOlMap',
      sourcemap: false,
      exports: 'named',
      globals: {
        'ol': 'ol'
      },
      plugins: [terser({
        compress: {
          drop_console: false, // 保留 console，方便调试
          drop_debugger: true
        },
        format: {
          comments: false // 移除注释
        }
      })]
    }
  ],
  external: ['ol'],
  plugins: [
    resolve({
      browser: true,
      preferBuiltins: false
    }),
    commonjs(),
    typescript({
      tsconfig: './tsconfig.json',
      declaration: true,
      declarationDir: './dist',
      rootDir: './src'
    })
  ]
};

